﻿<Page
    x:Name="pageRoot"
    x:Class="Ch9RSS_Universal.HubPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Ch9RSS_Universal"
    xmlns:data="using:Ch9RSS_Universal.Data"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:convert="using:Ch9RSS_Universal.Converters"
    RequestedTheme="Light"
    mc:Ignorable="d">

    <Page.Resources>
        <convert:ListLimitConverter x:Key="ListLimitConvert" />
        <x:Int32 x:Key="FeaturedLimit">10</x:Int32>
        <convert:ThumbConverter x:Key="ThumbConverter" />
        <x:Double x:Key="featureTargetSize">250</x:Double>
        <x:Double x:Key="featureTargetWidth">444</x:Double>
        <x:Double x:Key="standardTargetSize">175</x:Double>
        <x:Double x:Key="standardTargetWidth">230</x:Double>
        <!-- Grid-appropriate 310 by 260 pixel item template as seen in section 4 -->
        <DataTemplate x:Key="Standard310x260ItemTemplate">
            <Grid Height="250" Width="310" Margin="5,10,5,10">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Height="150">
                    <Image Source="{Binding ImagePath}" Stretch="Uniform" AutomationProperties.Name="{Binding Title}"/>
                </Border>
                <StackPanel Grid.Row="1" Margin="0,10,0,0">
                    <TextBlock Text="{Binding Title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap"/>
                    <TextBlock Text="{Binding Description}" Style="{StaticResource BodyTextBlockStyle}" MaxHeight="60" />
                </StackPanel>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="FeaturedItemsTemplate">
            <Grid Margin="5,10,5,10" Height="{StaticResource featureTargetSize}"
                  Width="{StaticResource featureTargetWidth}">
                <Border x:Name="parentBorder" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" >
                    <Image Source="{Binding thumbnail, Converter={StaticResource ThumbConverter}, ConverterParameter={StaticResource featureTargetSize}}" 
                                   Stretch="UniformToFill" 
                                   AutomationProperties.Name="{Binding Title}" 
                                   />
                </Border>
                <StackPanel VerticalAlignment="Bottom" Margin="0,0,0,0" Background="#CCF97600">
                    <TextBlock Text="{Binding title}" Foreground="White" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="2" Margin="10,5,5,10" FontSize="16" />
                </StackPanel>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="StandardItemsTemplate">
            <Grid Margin="10,10,20,10"  
                  Height="{StaticResource standardTargetSize}"
                 >
                <Border x:Name="parentBorder" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" >
                    <Image Source="{Binding thumbnail, Converter={StaticResource ThumbConverter}, ConverterParameter={StaticResource featureTargetSize}}" 
                                   Stretch="UniformToFill" 
                                   AutomationProperties.Name="{Binding Title}" 
                                   />
                </Border>
                <!--StackPanel VerticalAlignment="Bottom" Margin="0,0,0,0" Background="#CCF97600">
                    <TextBlock Text="{Binding title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="3" Margin="5,5,5,10" FontSize="16" />
                </-->
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="RecentItemsTemplate">
            <Grid Margin="5,10,5,10" Height="200">
                <Border x:Name="parentBorder" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" >
                    <Image Source="{Binding thumbnail, Converter={StaticResource ThumbConverter}, ConverterParameter={StaticResource featureTargetSize}}" 
                                   Stretch="UniformToFill" 
                                   />
                </Border>
                <StackPanel VerticalAlignment="Bottom" Orientation="Horizontal" Margin="0,0,0,0" 
                            Background="#CCF97600" 
                            >
                    <TextBlock Text="Left off at: " Foreground="White" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="2" Margin="5,5,5,5" FontSize="16" />
                    <TextBlock Text="{Binding LatestViewTime}" Foreground="White" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="2" Margin="5,5,5,5" FontSize="16" />
                </StackPanel>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="HubSectionHeaderTemplate">
            <Grid>
                <TextBlock Text="{Binding}" 
                           Margin="16,0,0,0"
                           Style="{StaticResource SubheaderTextBlockStyle}" />
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
    This grid acts as a root panel for the page.
  -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid Height="100" VerticalAlignment="Top">
            <Border Background="{StaticResource Ch9Orange}"  >
                <Image Margin="57,15,0,20" HorizontalAlignment="Left" Source="ms-appx:///Assets/Ch9Logo.png" />
            </Border>
        </Grid>
        <Hub SectionHeaderClick="Hub_SectionHeaderClick">
            <Hub.Header>
                <!-- Back button and page title -->
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <!-- Button  x:Name="backButton" Style="{StaticResource NavigationBackButtonNormalStyle}"
                        Margin="0,0,39,0" 
                        VerticalAlignment="Top"
                        Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/-->
                    <TextBlock x:Name="pageTitle" 
                               Text="Channel9 Viewer"
                               Margin="86,-30,0,0"
                               Style="{StaticResource HeaderTextBlockStyle}" 
                               Grid.Column="1"
                               Foreground="White"
                               VerticalAlignment="Top" 
                               IsHitTestVisible="false" TextWrapping="NoWrap" />
                </Grid>
            </Hub.Header>
            <HubSection x:Uid="Section1Header" Header="Featured" HeaderTemplate="{StaticResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <Grid>
                        <GridView x:Uid="FeaturedGridView" 
                                  ItemsSource="{Binding LimitFeaturedItems, Converter={StaticResource ListLimitConvert}, ConverterParameter={StaticResource FeaturedLimit}}"
                                  SelectionChanged="FeaturedItem_Changed"
                                  ItemTemplate="{StaticResource FeaturedItemsTemplate}"
                                  > 
                            
                        </GridView>   
                    </Grid>
                </DataTemplate>
            </HubSection>
            <HubSection x:Uid="Section3Header" Header="Shows" HeaderTemplate="{StaticResource HubSectionHeaderTemplate}" >
                <DataTemplate>
                    <GridView
                        x:Uid="ShowsGridView"
                        ItemsSource="{Binding ShowItems}"
                        SelectionChanged="ShowItem_Changed"
                        ItemTemplate="{StaticResource StandardItemsTemplate}">
                    </GridView>
                </DataTemplate>
            </HubSection>
            <HubSection x:Uid="Section2Header" Header="Series" HeaderTemplate="{StaticResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <Grid>
                        <GridView x:Uid="SeriesGridView" 
                                  ItemsSource="{Binding SeriesItems}"
                                  SelectionChanged="SeriesItem_Changed"
                                  ItemTemplate="{StaticResource StandardItemsTemplate}"
                                  >

                        </GridView>
                    </Grid>
                </DataTemplate>
            </HubSection>
            <HubSection Header="Recent" HeaderTemplate="{StaticResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <Grid>
                        <GridView x:Uid="RecentGridView" 
                                  ItemsSource="{Binding RecentlyViewed}"
                                  SelectionChanged="FeaturedItem_Changed"
                                  ItemTemplate="{StaticResource RecentItemsTemplate}"
                                  >

                        </GridView>
                    </Grid>
                </DataTemplate>
            </HubSection>
        </Hub>
    </Grid>
</Page>
